/*----------------------------------------------------------------------
  - File name      : STC8Ax_GPIO.c
  - Author         : Quark Team
  - Update date    : 2020-08-29                   
  -	Copyright      : Gevico Electronic studio   
  - Module comments: Layout module.
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include "STC8Ax_GPIO.h"
/*-----------------------------------------------------------------------
|                                 DATA                                  |
-----------------------------------------------------------------------*/
/* None */
/*-----------------------------------------------------------------------
|                               FUNCTION                                |
-----------------------------------------------------------------------*/

/*--------------------------------------------------------
| @Description: UART1 switch port control function       |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_UART1_SWPort(GPIOSWPort_Type Port)
{
	P_SW1 = (P_SW1 & 0x3F) | (Port << 6);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: UART2 switch port control function       |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_UART2_SWPort(GPIOSWPort_Type Port)
{
	if(Port < SW_PORT3)
	{
		P_SW2 = (P_SW2 & 0xFE) | (Port);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: UART3 switch port control function       |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_UART3_SWPort(GPIOSWPort_Type Port)
{
	if(Port < SW_PORT3)
	{
		P_SW2 = (P_SW2 & 0xFD) | (Port << 1);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: UART4 switch port control function       |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_UART4_SWPort(GPIOSWPort_Type Port)
{
	if(Port < SW_PORT3)
	{
		P_SW2 = (P_SW2 & 0xFB) | (Port << 2);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: COMP switch out port control function    |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_COMP_SWPort(GPIOSWPort_Type Port)
{
	if(Port < SW_PORT3)
	{
		P_SW2 = (P_SW2 & 0xF7) | (Port << 3);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: PCA switch port control function         |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_PCA_SWPort(GPIOSWPort_Type Port)
{
	P_SW1 = (P_SW1 & 0xCF) | (Port << 4);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PWM0 switch port control function        |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_PWM0_SWPort(GPIOSWPort_Type Port)
{
	if(Port <= SW_PORT3)
	{
		EAXFR_ENABLE();
		PWMxCR(PWM0CR_ADDRESS) = (PWMxCR(PWM0CR_ADDRESS) & 0xC7) | (Port << 3);
		EAXFR_DISABLE();
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: PWM1 switch port control function        |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_PWM1_SWPort(GPIOSWPort_Type Port)
{
	if(Port <= SW_PORT3)
	{
		EAXFR_ENABLE();
		PWMxCR(PWM1CR_ADDRESS) = (PWMxCR(PWM1CR_ADDRESS) & 0xC7) | (Port << 3);
		EAXFR_DISABLE();
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: PWM2 switch port control function        |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_PWM2_SWPort(GPIOSWPort_Type Port)
{
	if(Port <= SW_PORT3)
	{
		EAXFR_ENABLE();
		PWMxCR(PWM2CR_ADDRESS) = (PWMxCR(PWM2CR_ADDRESS) & 0xC7) | (Port << 3);
		EAXFR_DISABLE();
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: PWM3 switch port control function        |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_PWM3_SWPort(GPIOSWPort_Type Port)
{
	if(Port <= SW_PORT3)
	{
		EAXFR_ENABLE();
		PWMxCR(PWM3CR_ADDRESS) = (PWMxCR(PWM3CR_ADDRESS) & 0xC7) | (Port << 3);
		EAXFR_DISABLE();
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: PWM4 switch port control function        |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_PWM4_SWPort(GPIOSWPort_Type Port)
{
	if(Port <= SW_PORT3)
	{
		EAXFR_ENABLE();
		PWMxCR(PWM4CR_ADDRESS) = (PWMxCR(PWM4CR_ADDRESS) & 0xC7) | (Port << 3);
		EAXFR_DISABLE();
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: PWM5 switch port control function        |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_PWM5_SWPort(GPIOSWPort_Type Port)
{
	if(Port <= SW_PORT3)
	{
		EAXFR_ENABLE();
		PWMxCR(PWM5CR_ADDRESS) = (PWMxCR(PWM5CR_ADDRESS) & 0xC7) | (Port << 3);
		EAXFR_DISABLE();
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: PWM6 switch port control function        |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_PWM6_SWPort(GPIOSWPort_Type Port)
{
	if(Port <= SW_PORT3)
	{
		EAXFR_ENABLE();
		PWMxCR(PWM6CR_ADDRESS) = (PWMxCR(PWM6CR_ADDRESS) & 0xC7) | (Port << 3);
		EAXFR_DISABLE();
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: PWM7 switch port control function        |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_PWM7_SWPort(GPIOSWPort_Type Port)
{
	if(Port <= SW_PORT3)
	{
		EAXFR_ENABLE();
		PWMxCR(PWM7CR_ADDRESS) = (PWMxCR(PWM7CR_ADDRESS) & 0xC7) | (Port << 3);
		EAXFR_DISABLE();
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: SPI switch port control function         |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_SPI_SWPort(GPIOSWPort_Type Port)
{
	P_SW1 = (P_SW1 & 0xF3) | (Port << 2);
	return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: I2C switch port control function         |
| @param      : GPIOSWPort_Type Port                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE GPIO_I2C_SWPort(GPIOSWPort_Type Port)
{
	P_SW2 = (P_SW2 & 0xC0) | (Port << 4);
	return FSC_FAIL;
}

/*-----------------------------------------------------------------------
|          END OF FLIE        (C) COPYRIGHT Gevico Electronics          | 
-----------------------------------------------------------------------*/



